package com.zhuoyue.web.controller.system;

import com.zhuoyue.common.constant.HttpStatus;
import com.zhuoyue.common.core.controller.BaseController;
import com.zhuoyue.common.core.page.TableDataInfo;
import com.zhuoyue.system.domain.TblSecurityLog;
import com.zhuoyue.system.domain.po.TblSecurityLogPo;
import com.zhuoyue.system.mapper.TblSecurityLogMapper;
import com.zhuoyue.system.service.ITblSecurityLogService;
import com.zhuoyue.web.utils.OrgCodeUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


/**
 * logController
 *
 * @author hewenze
 * @date 2020-08-11
 */
@RestController
@Api(value = "报警日志接口", tags = "报警日志接口")
@RequestMapping("/system/log")
public class TblSecurityLogController extends BaseController {
    @Autowired
    private ITblSecurityLogService tblSecurityLogService;
    @Autowired
    private TblSecurityLogMapper tblSecurityLogMapper;

    @Autowired
    private OrgCodeUtils orgCodeUtils;


    int num = 0;

    /**
     * 查询log列表
     */
    @ApiOperation(value = "查询报警日志列表", notes = "查询报警日志列表")
    @GetMapping("/list")
    public TableDataInfo list(TblSecurityLogPo tblSecurityLogPo, HttpServletRequest request

    ) {


        tblSecurityLogPo.setOrganizationCode(orgCodeUtils.getOrgCode(request));
        // startPage();
        Integer page = (tblSecurityLogPo.getPageNum() - 1) * tblSecurityLogPo.getPageSize();
        Integer size = tblSecurityLogPo.getPageSize();

        Integer integer = this.tblSecurityLogService.selectByTimeCount(tblSecurityLogPo.getOrganizationCode(), tblSecurityLogPo.getAccount(), tblSecurityLogPo.getGatewayMac(), tblSecurityLogPo.getDeviceMac(), tblSecurityLogPo.getStartTime(), tblSecurityLogPo.getEndTime());
        List<TblSecurityLog> tblSecurityLogs = tblSecurityLogService.selectByTime(tblSecurityLogPo.getOrganizationCode(), tblSecurityLogPo.getAccount(), tblSecurityLogPo.getGatewayMac(), tblSecurityLogPo.getDeviceMac(), tblSecurityLogPo.getStartTime(), tblSecurityLogPo.getEndTime(), page, size);
        TableDataInfo dataTable = new TableDataInfo();
        dataTable.setTotal(integer);
        dataTable.setRows(tblSecurityLogs);
        dataTable.setCode(HttpStatus.SUCCESS);
        dataTable.setMsg("查询成功");

        return dataTable;

    }

    /*   *//**
     * 导出log列表
     *//*
    @Log(title = "log", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TblSecurityLog tblSecurityLog) throws IOException
    {
        List<DeviceManageDO> list = tblSecurityLogService.selectTblSecurityLogList(tblSecurityLog);
        ExcelUtil<DeviceManageDO> util = new ExcelUtil<DeviceManageDO>(DeviceManageDO.class);
        util.exportExcel(response, list, "log");
    }*/


}
